package com.webcat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.webcat.entity.po.DbConversationChatRecord;
import com.webcat.mapper.DbConversationChatRecordMapper;
import com.webcat.service.DbConversationChatRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DbConversationChatRecordServiceImpl implements DbConversationChatRecordService {

    @Resource
    private DbConversationChatRecordMapper dbConversationChatRecordMapper;

    @Override
    public void batchInsert(List<DbConversationChatRecord> dbConversationChatRecordList) {
        dbConversationChatRecordMapper.insertBatchSomeColumn(dbConversationChatRecordList);
    }

    @Override
    public void batchUpdate(List<DbConversationChatRecord> dbConversationChatRecordList) {
        dbConversationChatRecordMapper.alwaysUpdateSomeColumnById(dbConversationChatRecordList);
    }

    @Override
    public void insert(DbConversationChatRecord dbConversationChatRecord) {
        dbConversationChatRecordMapper.insert(dbConversationChatRecord);
    }

    @Override
    public List<DbConversationChatRecord> selectList(String conversationId) {
        LambdaQueryWrapper<DbConversationChatRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DbConversationChatRecord::getConversationId, conversationId);
        queryWrapper.orderByDesc(DbConversationChatRecord::getCreateTime);
        queryWrapper.eq(DbConversationChatRecord::getDeleteFlag, 0);
        return dbConversationChatRecordMapper.selectList(queryWrapper);
    }

    @Override
    public List<DbConversationChatRecord> selectList(String conversationId, int count) {
        LambdaQueryWrapper<DbConversationChatRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DbConversationChatRecord::getConversationId, conversationId);
        queryWrapper.orderByAsc(DbConversationChatRecord::getCreateTime);
        queryWrapper.eq(DbConversationChatRecord::getDeleteFlag, 0);
        IPage<DbConversationChatRecord> page = new Page<>(0, count);
        return dbConversationChatRecordMapper.selectPage(page, queryWrapper).getRecords();
    }
}
